HAL CORTEX How to Use ¶
- group CORTEX_How_To_Use
-
CORTEX main features ¶
The HAL CORTEX driver contains four main blocks: ¶
NVIC: Nested Vector Interrupt Controller
The NVIC is an embedded interrupt controller that supports low-latency interrupt processing.
It contains a configurable interrupt handling ability. Configured items can be:
Priority grouping that specifies the range of preemption priority and sub priority.
Preemption priority ability between interrupts.
Subpriority ability between interrupts.
SYSTICK: System Timer
The SysTick is a 24-bit countdown timer. It can be used as a simple counter or as a tick timer in a real-time operating system (RTOS).
MPU: Memory Protection Unit
The MPU allows privileged software to define memory regions, assign memory access permissions and memory attributes to each of them to improve the system reliability.
The MPU in this device supports 8 regions.
SCB: System Control Block
The SCB provides system information and system control that includes configuration, control and reporting of system fault exceptions.
How to use the CORTEX HAL module driver ¶
The CORTEX HAL driver can be used as follows: ¶
This driver provides HAL_CORTEX driver functions to configure the NVIC, SYSTICK, MPU, and SCB blocks.
How to configure NVIC interrupts using the CORTEX HAL driver:
Configure the NVIC priority grouping using the HAL_CORTEX_NVIC_SetPriorityGrouping() function once at startup.
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_0 is selected, IRQ preemption is no longer configurable. The pending IRQ priority is managed only by the sub-priority.
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_1 is selected, there is one bit for preemption priority and three bits for sub-priority.
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_2 is selected, there are two bits for preemption priority and two bits for sub-priority.
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_3 is selected, there are three bits for preemption priority and one bit for sub-priority.
When the HAL_CORTEX_NVIC_PRIORITY_GROUP_4 is selected, IRQ sub-priority is no longer configurable. The pending IRQ priority is managed only by the preemption priority.
Configure the priority of the selected IRQ channels using HAL_CORTEX_NVIC_SetPriority() function :
IRQ priority order (sorted by highest to lowest priority):
The lowest is the preemption priority numerical value, the highest is the preemption priority.
The lowest is the subpriority numerical value, the highest is the subpriority.
Get the priority grouping using HAL_CORTEX_NVIC_GetPriorityGrouping() function.
Get the priority of an interrupt using HAL_CORTEX_NVIC_GetPriority() function.
Enable the selected IRQ channels using HAL_CORTEX_NVIC_EnableIRQ() function.
Disable the selected IRQ channels using HAL_CORTEX_NVIC_DisableIRQ() function.
To check if an IRQ channel is enabled or not, use HAL_CORTEX_NVIC_IsEnabledIRQ() function.
To check if an IRQ channel is active or not, use HAL_CORTEX_NVIC_IsActiveIRQ() function.
To set pending bit of an interrupt, use HAL_CORTEX_NVIC_SetPendingIRQ() function.
To check if the IRQn channel is in pending state or not, use HAL_CORTEX_NVIC_IsPendingIRQ() function. When pending, use HAL_CORTEX_NVIC_ClearPendingIRQ() to clear the event.
When a system reset is needed within the application, use HAL_CORTEX_NVIC_SystemReset() function.
How to configure SYSTICK using the CORTEX HAL driver:
Configure the SYSTICK notification frequency and its source clock using HAL_CORTEX_SYSTICK_SetFreq() and HAL_CORTEX_SYSTICK_SetClkSource() functions.
To suspend the SYSTICK, use the HAL_CORTEX_SYSTICK_Suspend() function. When suspending, use HAL_CORTEX_SYSTICK_Resume() to resume the SYSTICK.
To handle the SYSTICK interrupts, use HAL_CORTEX_SYSTICK_IRQHandler() function.
How to configure MPU using the CORTEX HAL driver:
To configure a device memory attribute, use HAL_CORTEX_MPU_SetDeviceMemAttr() and, to configure normal memory (cache memory), use HAL_CORTEX_MPU_SetCacheMemAttr().
To get the device memory attributes configuration, use HAL_CORTEX_MPU_GetDeviceMemAttr().
To get the cache memory attributes configuration, use HAL_CORTEX_MPU_GetCacheMemAttr().
To configure an MPU region, use HAL_CORTEX_MPU_SetConfigRegion().
To get the MPU region configuration, use HAL_CORTEX_MPU_GetConfigRegion().
To enable or disable an MPU region, use HAL_CORTEX_MPU_EnableRegion() or HAL_CORTEX_MPU_DisableRegion().
To enable or disable the MPU, use HAL_CORTEX_MPU_Enable() or HAL_CORTEX_MPU_Disable().
To check if the MPU is enabled or not, use HAL_CORTEX_MPU_IsEnabled().
To check if the given MPU region is enabled or not, use HAL_CORTEX_MPU_IsEnabledRegion().
How to configure SCB using the CORTEX HAL driver:
When you need to get the CPU ID information within the application, use HAL_CORTEX_SCB_GetInfo().
Some exceptions can be redirected to their own IRQ channels or to the HARDFAULT IRQ channel. These exceptions are:
USAGE FAULT
BUS FAULT
MEMORY MANAGEMENT FAULT
When you need to redirect any exception to a HardFault, use HAL_CORTEX_SCB_EnableHardFaultEscalation().
When you need to disable any HardFault redirection, use HAL_CORTEX_SCB_DisableHardFaultEscalation().